<template>
<h1>循环指令</h1>
  <ul v-for="item in 5">
    <li>never out</li>
    <li>never out</li>
    <li>never out</li>
  </ul>
  <hr>
  <ul>
   <li v-for="a in arr">{{a}}</li>
  </ul>

  <table border="1px">
    <tr>
      <th>商品编号<</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品数量</th>
      <th>操作</th>
    </tr>
    <tr v-for="(a,index) in arr">
      <td>{{index+1}}</td>
      <td>{{a.name}}</td>
      <td>{{a.price}}</td>
      <td>{{a.num}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const arr = ref([
  {name:'小米手机',price:5000,num:100},
  {name:'华为手机',price:6000,num:200},
  {name:'苹果手机',price:7000,num:300},
  {name:'三星手机',price:8000,num:400},
  {name:'OPPO手机',price:9000,num:500},
]);

const del = (index)=>{
  if(confirm('确定删除吗？')){
    arr.value.splice(index,1);
  }
}
</script>


<style scoped>

</style>